package br.great.classes;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Vector;
import br.great.beans.User;
import br.great.beans.Wiki;

public class TradeText {

    int i1;
    int i2;
    int i3;
    String[] stringB;

    public String[] getInfo(String s) {
        i1 = s.indexOf("(");
        i2 = s.indexOf(")");
        i3 = s.indexOf(",");
        stringB = new String[2];
        stringB[0] = s.substring(i1 + 1, i3);
        if (s.substring(i3 + 1, i2).startsWith(" ")) {
            stringB[1] = s.substring(i3 + 1, i2).substring(1);
        } else {
            stringB[1] = s.substring(i3 + 1, i2);
        }
        return stringB;
    }

    public String[] getInfoWithEspace(String s) {
        i1 = s.indexOf("(");
        i2 = s.indexOf(")");
        i3 = s.indexOf(" ");
        stringB = new String[2];
        stringB[0] = s.substring(i1 + 1, i3);
        stringB[1] = s.substring(i3 + 1, i2);
        return stringB;
    }

    public static String tradeText(String s) {
        s = s.trim();
        if (s.contains("'")) {
            s = s.replace("'", "''");
        }
        return s;
    }

    public static String changeFirstLetter(String word) {
        StringBuffer sb = new StringBuffer(word);
        if (sb.length() > 0) {
            if (sb.charAt(0) >= 'a' || sb.charAt(0) <= 'z') {
                if (Character.isLowerCase(sb.charAt(0))) {
                    String s = Character.toUpperCase(sb.charAt(0)) + "";
                    sb.replace(0, 1, s);
                }
            }
        }
        return sb.toString();
    }

    public static Vector<String> stringToVectorStringBySpaceForTag(String s) {
        Vector<String> vs = stringToVectorStringBySpace(s);
        vs.add(s);

        return vs;
    }

    public static Vector<String> stringToVectorStringBySpace(String s) {
        Vector<String> vs = new Vector<String>();
        String[] tags = s.split(" ");
        for (int i = 0; i < tags.length; i++) {
            vs.add(tags[i]);
        }
        return vs;
    }

    public static Vector<User> stringToVectorUserByComma(String s) {
        Vector<User> vu = new Vector<User>();
        String[] sa = s.split(",");

        for (int i = 0; i < sa.length; i++) {
            User user = new User();
            user.setLogin(sa[i]); 
            vu.add(user);
        }
        return vu;
    }
    
    public static Vector<Wiki> stringToVectorWikiByEnter(String s, Vector<Wiki> vw) {
        Vector<Wiki> vs = new Vector<Wiki>();
        String[] sa = s.split("/n");
        for (int i = 0; i < sa.length; i++) {
            String sw = sa[i];
            for(int j=0; j<vw.size(); j++){
                if(vw.get(j).getTitle().equals(sw)){
                    vs.add(vw.get(j));
                }
            }
        }
        return vs;
    }
//    public static void main(String[] args) {
//        TradeText tr = new TradeText();
//        Vector<String> vs = tr.stringToVectorStringBySpaceForTag("don't push me");
//        for (int j = 0; j < vs.size(); j++) {
//            System.out.println(vs.get(j));
//        }
//    }
}   
    